package com.xjl.app.service;

import com.xjl.app.EntityDTO.DeviceDTO;
import com.xjl.app.EntityDTO.StationDTO;
import com.xjl.app.convert.StationDTODOConcert;
import com.xjl.app.domain.EntityDO.StationDO;
import com.xjl.app.domain.convert.StationDOConcert;
import com.xjl.app.infra.entity.Station;
import com.xjl.app.infra.service.StationService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@Slf4j
@Service
@RequiredArgsConstructor
public class StationDTOService {

    private final StationService stationService;
    private final StationDTODOConcert instance = StationDTODOConcert.INSTANCE;


    public Station save(StationDTO stationDTO) {
        StationDO stationDO = instance.toStationDO(stationDTO);
        Station station = instance.toStation(stationDO);

        if(stationService.save(station)){
            return station;
        }

        return null;
    }

    public StationDTO getStationById(String stationId) {
        Station byId = stationService.getById(stationId);
        if(byId==null){
            log.error("根据Id Station! id= {}",stationId);
            return null;
        }
        StationDTO stationDTO = instance.toStationDTO(byId);
        return stationDTO;
    }
}
